package com.duoduo.common.api.help;

import org.springframework.cglib.proxy.CallbackFilter;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

import java.io.Serializable;
import java.lang.reflect.Method;

@SuppressWarnings("serial")
public class DynamicProxyInnerUtil implements Serializable {
	
	@SuppressWarnings("unchecked")
	public static <T> T getProxy(T proxy, MethodInterceptor interceptor) {
		Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(proxy.getClass());
        enhancer.setCallbacks(new MethodInterceptor[]{interceptor});
        enhancer.setCallbackFilter(initCallbackFilter());
        return (T) enhancer.create();
	}
	
	private static final CallbackFilter initCallbackFilter(){
        return new CallbackFilter() {
            @Override
			public int accept(Method method) {
                return 0;
            }
        };

    }

}
